﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="不锈钢进度.aspx.cs" Inherits="syc.Produce.不锈钢进度" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
    protected string Notice = "";
    string sql ="select id,日期,cast(年计划 as float) as 年计划, cast(月计划 as float) as 月计划,cast(当日 as float) as 当日,cast(本月 as float) as 本月,cast(本年 as float) as 本年 from 不锈钢进度";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.Button_Query_Click(null, null);
        }
        else
        {
            this.SqlDataSource1.SelectCommand = this.SqlText.Text;
        }

    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        this.GridView1.SelectedIndex = e.NewEditIndex;
    }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {

        this.GridView1.SelectedIndex = -1;

        this.TextBox_Pager.Text = (this.GridView1.PageIndex + 1).ToString();
        this.Label_Pages.Text = " 共" + this.GridView1.PageCount.ToString() + "页 ";

        this.Button_Pager_First.CssClass = "pageturn-first-b";
        this.Button_Pager_First.Enabled = true;
        this.Button_Pager_Prev.CssClass = "pageturn-prev-b";
        this.Button_Pager_Prev.Enabled = true;
        this.Button_Pager_Next.CssClass = "pageturn-next-b";
        this.Button_Pager_Next.Enabled = true;
        this.Button_Pager_Last.CssClass = "pageturn-last-b";
        this.Button_Pager_Last.Enabled = true;
        if (this.GridView1.PageIndex == 0)
        {
            this.Button_Pager_Prev.CssClass = "pageturn-prev-g";
            this.Button_Pager_Prev.Enabled = false;
        }
        if (this.GridView1.PageIndex < 2)
        {
            this.Button_Pager_First.CssClass = "pageturn-first-g";
            this.Button_Pager_First.Enabled = false;
        }
        if (this.GridView1.PageIndex == this.GridView1.PageCount - 1 || this.GridView1.PageCount == 0)
        {
            this.Button_Pager_Next.CssClass = "pageturn-next-g";
            this.Button_Pager_Next.Enabled = false;

        }
        if (this.GridView1.PageIndex > this.GridView1.PageCount - 3)
        {
            this.Button_Pager_Last.CssClass = "pageturn-last-g";
            this.Button_Pager_Last.Enabled = false;
        }

    }
    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
        this.GridView1_DataBound(null, null);
    }
    protected void Pager_Click(object sender, EventArgs e)
    {
        if (sender.GetType().ToString() == "System.Web.UI.WebControls.Button")
        {
            switch (((Button)sender).CommandName)
            {
                case "--":
                    this.GridView1.PageIndex = 0;
                    break;
                case "-":
                    if (this.GridView1.PageIndex > 0) this.GridView1.PageIndex--;
                    break;
                case "+":
                    if (this.GridView1.PageIndex < this.GridView1.PageCount - 1) this.GridView1.PageIndex++;
                    break;
                case "++":
                    this.GridView1.PageIndex = this.GridView1.PageCount - 1;
                    break;
            }
        }
        else
        {

            int p;
            if (int.TryParse(TextBox_Pager.Text, out p))
            {
                if (p >= 1 && p <= this.GridView1.PageCount)
                {
                    this.GridView1.PageIndex = p - 1;
                }
            }
            TextBox_Pager.Text = (this.GridView1.PageIndex + 1).ToString();
        }

    }
    protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        Label_Total.Text = "共查询到 " + e.AffectedRows + " 项记录";
    }
    protected void PageSizeOption_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.GridView1.PageSize = int.Parse(this.PageSizeOption.Text);
    }
    private string GetState()
    {
        string state = "";
        DateTime d;
        if (DateTime.TryParse(this.Date1.Text, out d))
        {
            state += " and 日期>='" + d.ToShortDateString() + "'";
        }
        if (DateTime.TryParse(this.Date2.Text, out d))
        {
            state += " and 日期<='" + d.ToShortDateString() + "'";
        }

        if (state.StartsWith(" and"))
        {
            state = state.Substring(4);
        }
        if (state != "")
        {
            state = " where " + state;
        }
        return state;
    }
    protected void Button_Query_Click(object sender, EventArgs e)
    {
        string state = this.GetState();
        this.SqlText.Text = sql + state + " order by ID desc";
        this.GridView1.EditIndex = -1;
        this.SqlDataSource1.SelectCommand = "";
        this.SqlDataSource1.SelectCommand = this.SqlText.Text;
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "New")
        {
            this.SqlDataSource1.Insert();
        }
    }
</script>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>
<form id="form1" runat="server">
<asp:Label ID="SqlText" runat="server" Text="" Visible="false"></asp:Label>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>"
onselected="SqlDataSource1_Selected" 
InsertCommand="declare @日期 date, @年计划 numeric(18,3), @月计划 numeric(18,3), @当日 numeric(18,3), @本月 numeric(18,3), @本年 numeric(18,3);SELECT top 1 @日期=DATEADD(D,1,日期),@年计划=年计划, @月计划=月计划, @当日=当日, @本月=本月, @本年=本年 FROM  不锈钢进度 order by id desc;insert into 不锈钢进度 SELECT  isnull(@日期,getdate()),isnull(@年计划,0), isnull(@月计划,0), isnull(@当日,0), isnull(@本月,0), isnull(@本年,0);"
UpdateCommand="update 不锈钢进度 set 日期=@日期,年计划=@年计划, 月计划=@月计划, 当日=@当日, 本月=@本月, 本年=@本年 where id=@ID"
DeleteCommand="delete from 不锈钢进度 where id=@ID">
</asp:SqlDataSource>

<div id="wintop" class="wintop">不锈钢进度管理</div>

<asp:Panel ID="Panel1" runat="server" CssClass="panel">

起始日期：<asp:TextBox ID="Date1" runat="server" CssClass="textbox" Width="105px"></asp:TextBox><img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date1').value, document.getElementById('Date1'));" />
<span style="margin-left:10px;"></span>截止日期：<asp:TextBox ID="Date2" runat="server" CssClass="textbox" Width="105px"></asp:TextBox><img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date2').value, document.getElementById('Date2'));" />

<span style="margin-left:10px;"></span><asp:Button ID="Button_Query" runat="server" Text="查 询" UseSubmitBehavior="false" 
        CssClass="mbutton" onclick="Button_Query_Click" />
</asp:Panel>


<div class="gridframe">
    <div class="gridview">
    
        <table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolor="#e5cfab">
            <tr>
	            <td class="grid-title"><div style="float:left;margin-top:3px;">不锈钢进度</div><div style="float:right;">
                    <asp:DropDownList ID="PageSizeOption" runat="server" AutoPostBack="True" 
                        onselectedindexchanged="PageSizeOption_SelectedIndexChanged">
                    <asp:ListItem Value="10">10 项/页</asp:ListItem>
                    <asp:ListItem Value="20" Selected="True">20 项/页</asp:ListItem>
                    <asp:ListItem Value="30">30 项/页</asp:ListItem>
                    <asp:ListItem Value="50">50 项/页</asp:ListItem>
                    <asp:ListItem Value="100">100 项/页</asp:ListItem>
                    </asp:DropDownList></div></td>
	        </tr>
	        <tr>
	            <td class="grid-back">
                    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                        AutoGenerateColumns="False" CssClass="grid" DataKeyNames="ID" 
                        DataSourceID="SqlDataSource1"
                        PageSize="20"
                        GridLines="None" ondatabound="GridView1_DataBound" 
                        onpageindexchanged="GridView1_PageIndexChanged" AllowSorting="True" 
                        UseAccessibleHeader="False" onrowediting="GridView1_RowEditing" 
                        onrowcommand="GridView1_RowCommand" >
                        <PagerSettings Visible="False" />
                        <RowStyle CssClass="grid-row-normal" />
                        <Columns>
                            <asp:TemplateField HeaderText="">
                                <ItemTemplate>
                                    <asp:Button ID="Button_xz" runat="server" CommandName="Edit" Text="" CssClass="hide"/>
                                    <asp:Image ID="Image_icon" runat="server" ImageUrl="/Icons/online.gif" />
                                </ItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="20px" />
                            </asp:TemplateField>
                            
                            
                            <asp:TemplateField HeaderText="日期" SortExpression="日期">
                                <ItemTemplate>
                                    <asp:Label ID="Label_rq" runat="server" Text='<%# Eval("日期","{0:d}") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox_rq" runat="server" Text='<%# Bind("日期","{0:d}") %>' Width="100%" CssClass="textbox"></asp:TextBox>
                                </EditItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="80px" />
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="年计划" >
                                <ItemTemplate>
                                    <asp:Label ID="Label_njh" runat="server" Text='<%# Eval("年计划") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox_njh" runat="server" Text='<%# Bind("年计划") %>' Width="100%" CssClass="textbox"></asp:TextBox>
                                </EditItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="80px" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="月计划">
                                <ItemTemplate>
                                    <asp:Label ID="Label_yjh" runat="server" Text='<%# Eval("月计划") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox_yjh" runat="server" Text='<%# Bind("月计划") %>' Width="100%" CssClass="textbox"></asp:TextBox>
                                </EditItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="80px" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="当日生产">
                                <ItemTemplate>
                                    <asp:Label ID="Label_dr" runat="server" Text='<%# Eval("当日") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox_dr" runat="server" Text='<%# Bind("当日") %>' Width="100%" CssClass="textbox"></asp:TextBox>
                                </EditItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="80px" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="本月累计">
                                <ItemTemplate>
                                    <asp:Label ID="Label_by" runat="server" Text='<%# Eval("本月") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox_by" runat="server" Text='<%# Bind("本月") %>' Width="100%" CssClass="textbox"></asp:TextBox>
                                </EditItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="80px" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="年累计">
                                <ItemTemplate>
                                    <asp:Label ID="Label_bn" runat="server" Text='<%# Eval("本年") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox_bn" runat="server" Text='<%# Bind("本年") %>' Width="100%" CssClass="textbox"></asp:TextBox>
                                </EditItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="Center" Width="80px" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="操作" >
                                <HeaderTemplate>
                                    <asp:Button ID="Button_xz" runat="server" CommandName="New" Text="新 增" CssClass="smallbutton" UseSubmitBehavior="true"/>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Button ID="Button_sc" runat="server" CommandName="Delete" Text="删 除" CssClass="smallbutton" UseSubmitBehavior="true" OnClientClick="if(!del())return(false);"/>
                               </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Button ID="Button_gx" runat="server" CommandName="Update" Text="更 新" CssClass="smallbutton" UseSubmitBehavior="true"/>
                                </EditItemTemplate>
                                <HeaderStyle CssClass="grid-header" />
                                <ItemStyle CssClass="grid" HorizontalAlign="center" Width="50px" />
                            </asp:TemplateField>
                        </Columns>
                        <EmptyDataTemplate>
                            <asp:Button ID="Button_xz" runat="server" CommandName="New" Text="新 增" CssClass="smallbutton" UseSubmitBehavior="true"/>
                        </EmptyDataTemplate>
                        <EditRowStyle CssClass="grid-row-selected" />
                      </asp:GridView>
	            </td>
            </tr>
            <tr>
	            <td>   
	                <table width="100%">
	                    <tr>
	                        <td class="pagebar">
                                <asp:Button ID="Button_Pager_First" UseSubmitBehavior="false" runat="server" Text="" ToolTip="首页" 
                                    CssClass="pageturn-first-b" onclick="Pager_Click" CommandName="--" />
                                <asp:Button ID="Button_Pager_Prev" UseSubmitBehavior="false" runat="server" Text="" ToolTip="上一页" 
                                    CssClass="pageturn-prev-b" onclick="Pager_Click" CommandName="-" />
                                <input type="button" class="page-split" UseSubmitBehavior="false" disabled />第<asp:TextBox 
                                    ID="TextBox_Pager" AutoPostBack="True" runat="server" CssClass="pageturn" 
                                    ontextchanged="Pager_Click"></asp:TextBox>页<input type="button" class="page-split" disabled /><asp:Label ID="Label_Pages" UseSubmitBehavior="false" runat="server"></asp:Label><input type="button" class="page-split" disabled />
                                
                                <asp:Button ID="Button_Pager_Next" UseSubmitBehavior="false" runat="server" Text="" ToolTip="下一页" 
                                    CssClass="pageturn-next-b" onclick="Pager_Click" CommandName="+" />
                                <asp:Button ID="Button_Pager_Last" UseSubmitBehavior="false" runat="server" Text="" ToolTip="末页" 
                                    CssClass="pageturn-last-b" onclick="Pager_Click" CommandName="++" /><asp:Label ID="Label9" runat="server"></asp:Label><input type="button" class="page-split" disabled />
                            </td>
                            <td class="pagebar" align="right">
                                <asp:Label ID="Label_Total" runat="server"></asp:Label>
                            </td>
                        </tr>
                   </table>

	            </td>
            </tr>
        </table>
        

    </div>
</div>

</form>
<script>
    var notice = '<%=this.Notice %>';
    if (notice != '') {
        parent.showmsgbox(notice);
    }
</script>
<script>

    var textboxs = document.getElementsByTagName("input");
    var i;
    for (i = 0; i < textboxs.length; i++) {
        if (textboxs[i].className == "textbox") {
            //textboxs[i].onchange = function(e) { this.className = "textbox-changed"; };
            textboxs[i].onfocus = function(e) { this.select(); };
        }
        else if (textboxs[i].className == "pageturn" || textboxs[i].className == "intxt1" || textboxs[i].className == "intxt2") {
            textboxs[i].onfocus = function(e) { this.select(); };
        }
    }
    var rows = document.getElementsByTagName("tr");
    for (i = 0; i < rows.length; i++) {

        if (rows[i].className == "grid-row-normal") {
            rows[i].onmouseover = function() { this.className = "grid-row-bright"; };
            rows[i].onmouseout = function() { this.className = "grid-row-normal"; };
            rows[i].onclick = selectRow;
        }
    }

    document.onkeydown = function(e) {
        if (!e) e = window.event;
        var tag = e.srcElement;
        if (!tag) tag = e.target;
        if (tag.tagName == "INPUT" && tag.className == "textbox" || tag.tagName == "SELECT") {
            if (e.keyCode == 13) e.keyCode = 9;
        }
    }
    function del() {
        return confirm('确认要删除该条记录吗？');
    }
</script>
</body>
</html>

